// Basic datetype
var a = Array(9);
a.fill(1, 0, a.length); // fill(value, start, end)
function geneArr(num) {      
    var arr = [];   
    for (let i = 0; i < num; i++) {       
        arr.push(i);          
    }                   
    return arr;               
}

// string to number
console.log(String(3.12));
console.log(Number("12"));
console.log(parseInt("121"));
console.log(parseFloat("12.3"));

// indexOf lastIndexOf
var ok = "Are you ok!";
var good = [ok, ok, ok].join(" "); 
console.log(good.lastIndexOf("ok"));
console.log(good.concat(ok));

// ok.repeat(2) --> "Are you ok!Are you ok!"
function myRepeat(instr, num) 
{
    var temp = Array(num); // 有位子才能填充  
    temp.fill(instr, 0, num);          
    return temp.join(""); 
}
console.log(myRepeat(ok, 6));

// good.includes("Are") startsWith, endsWith
// split   分离子串
console.log(ok.split());
console.log(ok.split(""));  // ["A", "r", "e", " ", "y", "o", "u", " ", "o", "k", "!"]
console.log(ok.split(" ")); // ["Are", "you", "ok!"]
 
// splice  从一个字符串提取片段并作为新字符串返回。
// substring()的参数表示起始和结束索引
// substr()方法的参数表示起始索和字符的长度：
var text = 'Mozilla';
console.log(text.substring(2,5)); // => "zil"
console.log(text.substr(2,3)); // => "zil"

// trim	   去掉字符串开头和结尾的空白字符。
console.log("  are you all right      ".trim());

function reverStr(instr) 
{   // quick version
    var result = undefined;
	if ((typeof instr) == "string" ) {
		result = instr.split("").reverse().join(""); 
    }
	return result;
}

function reverseStr(in_str) 
{             
    var list = [];                  
    for (let s of in_str) {          
       list.push(s);                             
    }  
	return list.reverse().join("");
}

// toLowerCase, toUpperCase
function showStr(in_str) 
{             
    for (let s of in_str) {          
        console.log(s);        
    }             
}

// advance in regexp
// match, replace, search
Math.max.apply(null, [1, 2, 3]);


